



//
//  Tabbar.swift
//  mywei
//
//  Created by myd on 15/12/15.
//  Copyright © 2015年 myd1. All rights reserved.
//

import UIKit

protocol chilkadd1 : NSObjectProtocol
{
    func chilkadd(chilk : Tabbar)
}

class Tabbar: UITabBar {

    weak var dele : chilkadd1?
    override func layoutSubviews() {
        super.layoutSubviews()
       let sizew=self.bounds.width/5
        let  frame = CGRectMake(0, 0, sizew, self.bounds.height)
        var a = 0
     
        for vv in self.subviews
        {

       if vv is UIControl && !(vv is UIButton)
       {
         vv.frame=CGRectOffset(frame,sizew*CGFloat(a), 0)
        a += a == 1 ? 2 : 1
            }
           
        }
            self.bb.frame=CGRectOffset(frame,sizew*2,0)
        self.addSubview(self.bb)
        }
    
    
    lazy var bb : UIButton = {
   let  bb1 = UIButton()
        bb1 .setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        bb1.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        bb1.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        bb1.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Selected)
        bb1.addTarget(self, action:"chilk", forControlEvents: UIControlEvents.TouchUpInside)
    
            return bb1
    }()
func chilk ()
{
    if let _ = dele
    {
   self.dele?.chilkadd(self)
    }
    }
}
